package br.com.rafael.gestorinvestimentos.DAO;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.rafael.gestorinvestimentos.model.Termo;

public class TermoDAO{
	private Session session;
	
	public TermoDAO(Session session){
		this.session = session;
	}	
	
	public void insert (Termo termo){
		this.session.save(termo);
	}
	
	public void update (Termo termo){
		this.session.merge(termo);
	}
	
	public void delete (Termo termo){
		this.session.delete(termo);
	}
	
	public Termo getTermo (int id){
		return (Termo) session.load(Termo.class, id);
	
	}
	
	public Termo getTermo (String ticker){
		Query q = this.session.createQuery("from Termo as termo where termo.ticker = :termoTicker").setParameter("termoTicker", ticker);
		return (Termo) q.uniqueResult();
	}
	
	public Termo getTermoNome (String nome){
		Query q = this.session.createQuery("from Termo as termo where termo.nome = :termoNome").setParameter("termoNome", nome);
		return (Termo) q.uniqueResult();
	}
		
	public List getList (){
		return this.session.createCriteria(Termo.class).list();
	}


}
